﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BoldBrick.OneIntranet.HR.Resources;
using Microsoft.SharePoint;

namespace BoldBrick.OneIntranet.HR.WebParts.HRWorkflowStatisticsWebPart
{
	[ToolboxItemAttribute(false)]
	public class HRWorkflowStatisticsWebPart : WebPart
	{
		#region ------ Properties -----------------------------------------------------------------

		/// <summary>
		/// Id of workflow to show
		/// </summary>
		[WebBrowsable(false)]
		[Personalizable(PersonalizationScope.Shared)]
		public int WorkflowID { get; set; }
		
		/// <summary>
		/// Status of shown workflow
		/// </summary>
		[WebBrowsable(false)]
		[Personalizable(PersonalizationScope.Shared)]
		public WorkflowStatus WorkflowStatus { get; set; }

		#endregion
		
		#region ------ Load Control ---------------------------------------------------------------

		private const string _ascxPath = @"~/_CONTROLTEMPLATES/BoldBrick.OneIntranet.HR.WebParts/HRWorkflowStatisticsWebPart/HRWorkflowStatisticsWebPartUserControl.ascx";

		protected override void CreateChildControls()
		{
			HRWorkflowStatisticsWebPartUserControl control = Page.LoadControl(_ascxPath) as HRWorkflowStatisticsWebPartUserControl;
			if (control != null)
			{
				control.WorkflowID = this.WorkflowID;
				control.WorkflowStatus = this.WorkflowStatus;
				this.Controls.Add(control);
			}
		
		}

		public override EditorPartCollection CreateEditorParts()
		{
			List<EditorPart> editorParts = new List<EditorPart>();
			HRWorkflowStatisticsEditorPart editorPart = new HRWorkflowStatisticsEditorPart
			{
				Title = ResourceBuilder.GetResource("HRWorkflowStatisticsWebPart_EditorPart_Title", SPContext.Current.Web.Language),
				ID = this.ID + "_HRWorkflowStatisticsEditorPart"
			};
			editorParts.Add(editorPart);

			EditorPartCollection baseparts = base.CreateEditorParts();
			return new EditorPartCollection(baseparts, editorParts);
		}

		#endregion
	}
}
